from django_redis import get_redis_connection


class RedisCode:
    def __init__(self):
        self.conn = get_redis_connection('default')

    # 存储一个字符串
    def setstr(self, key, value):
        self.conn.set(key, value)

    # 删除字符串
    def delstr(self, key):
        self.conn.unlink(key)

    # 设置一个过期时间
    def setex(self, key, value, time):
        self.conn.setex(key, value, time)

    # 获取一个字符串
    def getstr(self, key):
        val = self.conn.get(key)
        if val:
            return val.decode('utf-8')
        else:
            return None


# redis_tool = RedisCode()



